home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’96 / VideoFolder 1.0a / Source / MoreFiles 1.4.1 / MoreFiles.c < prev    next >
Text File  |  1995-12-21  |  16KB  |  569 lines

  1. /*
  2. **    Apple Macintosh Developer Technical Support
  3. **
  4. **    The long lost high-level and FSSpec File Manager functions.
  5. **
  6. **    by Jim Luther, Apple Developer Technical Support Emeritus
  7. **
  8. **    File:        MoreFiles.c
  9. **
  10. **    Copyright © 1992-1995 Apple Computer, Inc.
  11. **    All rights reserved.
  12. **
  13. **    You may incorporate this sample code into your applications without
  14. **    restriction, though the sample code has been provided "AS IS" and the
  15. **    responsibility for its operation is 100% yours.  However, what you are
  16. **    not permitted to do is to redistribute the source as "DSC Sample Code"
  17. **    after having made changes. If you're going to re-distribute the source,
  18. **    we require that you make it clear in the source that the code was
  19. **    descended from Apple Sample Code, but that you've made changes.
  20. */
  21.  
  22. #include <Types.h>
  23. #include <Errors.h>
  24. #include <Files.h>
  25. #include "MoreFiles.h"
  26.  
  27. /*****************************************************************************/
  28.  
  29. pascal    OSErr    HGetVolParms(StringPtr volName,
  30.                              short vRefNum,
  31.                              GetVolParmsInfoBuffer *volParmsInfo,
  32.                              long *infoSize)
  33. {
  34.     HParamBlockRec pb;
  35.     OSErr error;
  36.  
  37.     pb.ioParam.ioNamePtr = volName;
  38.     pb.ioParam.ioVRefNum = vRefNum;
  39.     pb.ioParam.ioBuffer = (Ptr)volParmsInfo;
  40.     pb.ioParam.ioReqCount = *infoSize;
  41.     error = PBHGetVolParmsSync(&pb);
  42.     *infoSize = pb.ioParam.ioActCount;
  43.     return ( error );
  44. }
  45.  
  46. /*****************************************************************************/
  47.  
  48. pascal    OSErr    HCreateMinimum(short vRefNum,
  49.                                long dirID,
  50.                                ConstStr255Param fileName)
  51. {
  52.     HParamBlockRec pb;
  53.  
  54.     pb.fileParam.ioNamePtr = (StringPtr)fileName;
  55.     pb.fileParam.ioVRefNum = vRefNum;
  56.     pb.ioParam.ioVersNum = 0;
  57.     pb.fileParam.ioDirID = dirID;
  58.     return ( PBHCreateSync(&pb) );
  59. }
  60.  
  61. /*****************************************************************************/
  62.  
  63. pascal    OSErr    FSpCreateMinimum(const FSSpec *spec)
  64. {
  65.     return ( HCreateMinimum(spec->vRefNum, spec->parID, spec->name) );
  66. }
  67.  
  68. /*****************************************************************************/
  69.  
  70. pascal    OSErr    ExchangeFiles(short vRefNum,
  71.                               long srcDirID,
  72.                               ConstStr255Param srcName,
  73.                               long dstDirID,
  74.                               ConstStr255Param dstName)
  75. {
  76.     HParamBlockRec pb;
  77.  
  78.     pb.fidParam.ioVRefNum = vRefNum;
  79.     pb.fidParam.ioSrcDirID = srcDirID;
  80.     pb.fidParam.ioNamePtr = (StringPtr)srcName;
  81.     pb.fidParam.ioDestDirID = dstDirID;
  82.     pb.fidParam.ioDestNamePtr = (StringPtr)dstName;
  83.     return ( PBExchangeFilesSync(&pb) );
  84. }
  85.  
  86. /*****************************************************************************/
  87.  
  88. pascal    OSErr    ResolveFileIDRef(StringPtr volName,
  89.                                  short vRefNum,
  90.                                  long fileID,
  91.                                  long *parID,
  92.                                  StringPtr fileName)
  93. {
  94.     HParamBlockRec pb;
  95.     OSErr error;
  96.     Str255 tempStr;
  97.     
  98.     tempStr[0] = 0;
  99.     if ( volName != NULL )
  100.         BlockMoveData(volName, tempStr, volName[0] + 1);
  101.     pb.fidParam.ioNamePtr = (StringPtr)tempStr;
  102.     pb.fidParam.ioVRefNum = vRefNum;
  103.     pb.fidParam.ioFileID = fileID;
  104.     error = PBResolveFileIDRefSync(&pb);
  105.     *parID = pb.fidParam.ioSrcDirID;
  106.     if ( fileName != NULL )
  107.         BlockMoveData(tempStr, fileName, tempStr[0] + 1);
  108.     return ( error );
  109. }
  110.  
  111. /*****************************************************************************/
  112.  
  113. pascal    OSErr    CreateFileIDRef(short vRefNum,
  114.                                 long parID,
  115.                                 ConstStr255Param fileName,
  116.                                 long *fileID)
  117. {
  118.     HParamBlockRec pb;
  119.     OSErr error;
  120.  
  121.     pb.fidParam.ioNamePtr = (StringPtr)fileName;
  122.     pb.fidParam.ioVRefNum = vRefNum;
  123.     pb.fidParam.ioSrcDirID = parID;
  124.     error = PBCreateFileIDRefSync(&pb);
  125.     *fileID = pb.fidParam.ioFileID;
  126.     return ( error );
  127. }
  128.  
  129. /*****************************************************************************/
  130.  
  131. pascal    OSErr    FSpCreateFileIDRef(const FSSpec *spec,
  132.                                    long *fileID)
  133. {
  134.     return ( CreateFileIDRef(spec->vRefNum, spec->parID, spec->name, fileID) );
  135. }
  136.  
  137. /*****************************************************************************/
  138.  
  139. pascal    OSErr    DeleteFileIDRef(StringPtr volName,
  140.                                 short vRefNum,
  141.                                 long fileID)
  142. {
  143.     HParamBlockRec pb;
  144.  
  145.     pb.fidParam.ioNamePtr = volName;
  146.     pb.fidParam.ioVRefNum = vRefNum;
  147.     pb.fidParam.ioFileID = fileID;
  148.     return ( PBDeleteFileIDRefSync(&pb) );
  149. }
  150.  
  151. /*****************************************************************************/
  152.  
  153. pascal    OSErr    FlushFile(short refNum)
  154. {
  155.     ParamBlockRec pb;
  156.  
  157.     pb.ioParam.ioRefNum = refNum;
  158.     return ( PBFlushFileSync(&pb) );
  159. }
  160.  
  161. /*****************************************************************************/
  162.  
  163. pascal    OSErr    LockRange(short refNum,
  164.                           long rangeLength,
  165.                           long rangeStart)
  166. {
  167.     ParamBlockRec pb;
  168.  
  169.     pb.ioParam.ioRefNum = refNum;
  170.     pb.ioParam.ioReqCount = rangeLength;
  171.     pb.ioParam.ioPosMode = fsFromStart;
  172.     pb.ioParam.ioPosOffset = rangeStart;
  173.     return ( PBLockRangeSync(&pb) );
  174. }
  175.  
  176. /*****************************************************************************/
  177.  
  178. pascal    OSErr    UnlockRange(short refNum,
  179.                             long rangeLength,
  180.                             long rangeStart)
  181. {
  182.     ParamBlockRec pb;
  183.  
  184.     pb.ioParam.ioRefNum = refNum;
  185.     pb.ioParam.ioReqCount = rangeLength;
  186.     pb.ioParam.ioPosMode = fsFromStart;
  187.     pb.ioParam.ioPosOffset = rangeStart;
  188.     return ( PBUnlockRangeSync(&pb) );
  189. }
  190.  
  191. /*****************************************************************************/
  192.  
  193. pascal    OSErr    GetForeignPrivs(short vRefNum,
  194.                                 long dirID,
  195.                                 StringPtr name,
  196.                                 void *foreignPrivBuffer,
  197.                                 long *foreignPrivSize,
  198.                                 long *foreignPrivInfo1,
  199.                                 long *foreignPrivInfo2,
  200.                                 long *foreignPrivInfo3,
  201.                                 long *foreignPrivInfo4)
  202. {
  203.     HParamBlockRec pb;
  204.     OSErr error;
  205.  
  206.     pb.foreignPrivParam.ioNamePtr = name;
  207.     pb.foreignPrivParam.ioVRefNum = vRefNum;
  208.     pb.foreignPrivParam.ioForeignPrivDirID = dirID;    
  209.     pb.foreignPrivParam.ioForeignPrivBuffer = (Ptr)foreignPrivBuffer;
  210.     pb.foreignPrivParam.ioForeignPrivReqCount = *foreignPrivSize;
  211.     error = PBGetForeignPrivsSync(&pb);
  212.     *foreignPrivSize = pb.foreignPrivParam.ioForeignPrivActCount;
  213.     *foreignPrivInfo1 = pb.foreignPrivParam.ioForeignPrivInfo1;
  214.     *foreignPrivInfo2 = pb.foreignPrivParam.ioForeignPrivInfo2;
  215.     *foreignPrivInfo3 = pb.foreignPrivParam.ioForeignPrivInfo3;
  216.     *foreignPrivInfo4 = pb.foreignPrivParam.ioForeignPrivInfo4;
  217.     return ( error );
  218. }
  219.  
  220. /*****************************************************************************/
  221.  
  222. pascal    OSErr    FSpGetForeignPrivs(const FSSpec *spec,
  223.                                    void *foreignPrivBuffer,
  224.                                    long *foreignPrivSize,
  225.                                    long *foreignPrivInfo1,
  226.                                    long *foreignPrivInfo2,
  227.                                    long *foreignPrivInfo3,
  228.                                    long *foreignPrivInfo4)
  229. {
  230.     return ( GetForeignPrivs(spec->vRefNum, spec->parID, (StringPtr)spec->name,
  231.                              foreignPrivBuffer, foreignPrivSize,
  232.                              foreignPrivInfo1, foreignPrivInfo2,
  233.                              foreignPrivInfo3, foreignPrivInfo4) );
  234. }
  235.  
  236. /*****************************************************************************/
  237.  
  238. pascal    OSErr    SetForeignPrivs(short vRefNum,
  239.                                 long dirID,
  240.                                 StringPtr name,
  241.                                 void *foreignPrivBuffer,
  242.                                 long *foreignPrivSize,
  243.                                 long foreignPrivInfo1,
  244.                                 long foreignPrivInfo2,
  245.                                 long foreignPrivInfo3,
  246.                                 long foreignPrivInfo4)
  247. {
  248.     HParamBlockRec pb;
  249.     OSErr error;
  250.  
  251.     pb.foreignPrivParam.ioNamePtr = name;
  252.     pb.foreignPrivParam.ioVRefNum = vRefNum;
  253.     pb.foreignPrivParam.ioForeignPrivDirID = dirID;    
  254.     pb.foreignPrivParam.ioForeignPrivBuffer = (Ptr)foreignPrivBuffer;
  255.     pb.foreignPrivParam.ioForeignPrivReqCount = *foreignPrivSize;
  256.     pb.foreignPrivParam.ioForeignPrivInfo1 = foreignPrivInfo1;
  257.     pb.foreignPrivParam.ioForeignPrivInfo2 = foreignPrivInfo2;
  258.     pb.foreignPrivParam.ioForeignPrivInfo3 = foreignPrivInfo3;
  259.     pb.foreignPrivParam.ioForeignPrivInfo4 = foreignPrivInfo4;
  260.     error = PBSetForeignPrivsSync(&pb);
  261.     *foreignPrivSize = pb.foreignPrivParam.ioForeignPrivActCount;
  262.     return ( error );
  263. }
  264.  
  265. /*****************************************************************************/
  266.  
  267. pascal    OSErr    FSpSetForeignPrivs(const FSSpec *spec,
  268.                                    void *foreignPrivBuffer,
  269.                                    long *foreignPrivSize,
  270.                                    long foreignPrivInfo1,
  271.                                    long foreignPrivInfo2,
  272.                                    long foreignPrivInfo3,
  273.                                    long foreignPrivInfo4)
  274. {
  275.     return ( SetForeignPrivs(spec->vRefNum, spec->parID, (StringPtr)spec->name,
  276.                              foreignPrivBuffer, foreignPrivSize,
  277.                              foreignPrivInfo1, foreignPrivInfo2,
  278.                              foreignPrivInfo3, foreignPrivInfo4) );
  279. }
  280.  
  281. /*****************************************************************************/
  282.  
  283. pascal    OSErr    HGetLogInInfo(StringPtr volName,
  284.                               short vRefNum,
  285.                               short *loginMethod,
  286.                               StringPtr userName)
  287. {
  288.     HParamBlockRec pb;
  289.     OSErr error;
  290.  
  291.     pb.objParam.ioNamePtr = volName;
  292.     pb.objParam.ioVRefNum = vRefNum;
  293.     pb.objParam.ioObjNamePtr = userName;
  294.     error = PBHGetLogInInfoSync(&pb);
  295.     *loginMethod = pb.objParam.ioObjType;
  296.     return ( error );
  297. }
  298.  
  299. /*****************************************************************************/
  300.  
  301. pascal    OSErr    HGetDirAccess(short vRefNum,
  302.                               long dirID,
  303.                               StringPtr name,
  304.                               long *ownerID,
  305.                               long *groupID,
  306.                               long *accessRights)
  307. {
  308.     HParamBlockRec pb;
  309.     OSErr error;
  310.  
  311.     pb.accessParam.ioNamePtr = name;
  312.     pb.accessParam.ioVRefNum = vRefNum;
  313.     pb.fileParam.ioDirID = dirID;
  314.     error = PBHGetDirAccessSync(&pb);
  315.     *ownerID = pb.accessParam.ioACOwnerID;
  316.     *groupID = pb.accessParam.ioACGroupID;
  317.     *accessRights = pb.accessParam.ioACAccess;
  318.     return ( error );
  319. }
  320.  
  321. /*****************************************************************************/
  322.  
  323. pascal    OSErr    FSpGetDirAccess(const FSSpec *spec,
  324.                                 long *ownerID,
  325.                                 long *groupID,
  326.                                 long *accessRights)
  327. {
  328.     return ( HGetDirAccess(spec->vRefNum, spec->parID, (StringPtr)spec->name,
  329.                            ownerID, groupID, accessRights) );
  330. }
  331.  
  332. /*****************************************************************************/
  333.  
  334. pascal    OSErr    HSetDirAccess(short vRefNum,
  335.                               long dirID,
  336.                               StringPtr name,
  337.                               long ownerID,
  338.                               long groupID,
  339.                               long accessRights)
  340. {
  341.     HParamBlockRec pb;
  342.  
  343.     pb.accessParam.ioNamePtr = name;
  344.     pb.accessParam.ioVRefNum = vRefNum;
  345.     pb.fileParam.ioDirID = dirID;
  346.     pb.accessParam.ioACOwnerID = ownerID;
  347.     pb.accessParam.ioACGroupID = groupID;
  348.     pb.accessParam.ioACAccess = accessRights;
  349.     return ( PBHSetDirAccessSync(&pb) );
  350. }
  351.  
  352. /*****************************************************************************/
  353.  
  354. pascal    OSErr    FSpSetDirAccess(const FSSpec *spec,
  355.                                 long ownerID,
  356.                                 long groupID,
  357.                                 long accessRights)
  358. {
  359.     return ( HSetDirAccess(spec->vRefNum, spec->parID, (StringPtr)spec->name,
  360.                            ownerID, groupID, accessRights) );
  361. }
  362.  
  363. /*****************************************************************************/
  364.  
  365. pascal    OSErr    HMapID(StringPtr volName,
  366.                        short vRefNum,
  367.                        long ugID,
  368.                        short objType,
  369.                        StringPtr name)
  370. {
  371.     HParamBlockRec pb;
  372.  
  373.     pb.objParam.ioNamePtr = volName;
  374.     pb.objParam.ioVRefNum = vRefNum;
  375.     pb.objParam.ioObjType = objType;
  376.     pb.objParam.ioObjNamePtr = name;
  377.     pb.objParam.ioObjID = ugID;
  378.     return ( PBHMapIDSync(&pb) );
  379. }
  380.  
  381. /*****************************************************************************/
  382.  
  383. pascal    OSErr    HMapName(StringPtr volName,
  384.                          short vRefNum,
  385.                          ConstStr255Param name,
  386.                          short objType,
  387.                          long *ugID)
  388. {
  389.     HParamBlockRec pb;
  390.     OSErr error;
  391.  
  392.     pb.objParam.ioNamePtr = volName;
  393.     pb.objParam.ioVRefNum = vRefNum;
  394.     pb.objParam.ioObjType = objType;
  395.     pb.objParam.ioObjNamePtr = (StringPtr)name;
  396.     error = PBHMapNameSync(&pb);
  397.     *ugID = pb.objParam.ioObjID;
  398.     return ( error );
  399. }
  400.  
  401. /*****************************************************************************/
  402.  
  403. pascal    OSErr    HCopyFile(short srcVRefNum,
  404.                           long srcDirID,
  405.                           ConstStr255Param srcName,
  406.                           short dstVRefNum,
  407.                           long dstDirID,
  408.                           StringPtr dstPathname,
  409.                           StringPtr copyName)
  410. {
  411.     HParamBlockRec pb;
  412.  
  413.     pb.copyParam.ioVRefNum = srcVRefNum;
  414.     pb.copyParam.ioDirID = srcDirID;
  415.     pb.copyParam.ioNamePtr = (StringPtr)srcName;
  416.     pb.copyParam.ioDstVRefNum = dstVRefNum;
  417.     pb.copyParam.ioNewDirID = dstDirID;
  418.     pb.copyParam.ioNewName = dstPathname;
  419.     pb.copyParam.ioCopyName = copyName;
  420.     return ( PBHCopyFileSync(&pb) );
  421. }
  422.  
  423. /*****************************************************************************/
  424.  
  425. pascal    OSErr    FSpCopyFile(const FSSpec *srcSpec,
  426.                             const FSSpec *dstSpec,
  427.                             StringPtr copyName)
  428. {
  429.     return ( HCopyFile(srcSpec->vRefNum, srcSpec->parID, srcSpec->name,
  430.                        dstSpec->vRefNum, dstSpec->parID,
  431.                        (StringPtr)dstSpec->name, copyName) );
  432. }
  433.  
  434. /*****************************************************************************/
  435.  
  436. pascal    OSErr    HMoveRename(short vRefNum,
  437.                             long srcDirID,
  438.                             ConstStr255Param srcName,
  439.                             long dstDirID,
  440.                             StringPtr dstpathName,
  441.                             StringPtr copyName)
  442. {
  443.     HParamBlockRec pb;
  444.  
  445.     pb.copyParam.ioVRefNum = vRefNum;
  446.     pb.copyParam.ioDirID = srcDirID;
  447.     pb.copyParam.ioNamePtr = (StringPtr)srcName;
  448.     pb.copyParam.ioNewDirID = dstDirID;
  449.     pb.copyParam.ioNewName = dstpathName;
  450.     pb.copyParam.ioCopyName = copyName;
  451.     return ( PBHMoveRenameSync(&pb) );
  452. }
  453.  
  454. /*****************************************************************************/
  455.  
  456. pascal    OSErr    FSpMoveRename(const FSSpec *srcSpec,
  457.                               const FSSpec *dstSpec,
  458.                               StringPtr copyName)
  459. {
  460.     /* make sure the FSSpecs refer to the same volume */
  461.     if ( srcSpec->vRefNum != dstSpec->vRefNum )
  462.         return ( diffVolErr );
  463.     return ( HMoveRename(srcSpec->vRefNum, srcSpec->parID, srcSpec->name, 
  464.                          dstSpec->parID, (StringPtr)dstSpec->name, copyName) );
  465. }
  466.  
  467. /*****************************************************************************/
  468.  
  469. pascal    OSErr    GetVolMountInfoSize(StringPtr volName,
  470.                                     short vRefNum,
  471.                                     short *size)
  472. {
  473.     ParamBlockRec pb;
  474.  
  475.     pb.ioParam.ioNamePtr = volName;
  476.     pb.ioParam.ioVRefNum = vRefNum;
  477.     pb.ioParam.ioBuffer = (Ptr)size;
  478.     return ( PBGetVolMountInfoSize(&pb) );
  479. }
  480.  
  481. /*****************************************************************************/
  482.  
  483. pascal    OSErr    GetVolMountInfo(StringPtr volName,
  484.                                 short vRefNum,
  485.                                 void *volMountInfo)
  486. {
  487.     ParamBlockRec pb;
  488.  
  489.     pb.ioParam.ioNamePtr = volName;
  490.     pb.ioParam.ioVRefNum = vRefNum;
  491.     pb.ioParam.ioBuffer = (Ptr)volMountInfo;
  492.     return ( PBGetVolMountInfo(&pb) );
  493. }
  494.  
  495. /*****************************************************************************/
  496.  
  497. pascal    OSErr    VolumeMount(void *volMountInfo,
  498.                             short *vRefNum)
  499. {
  500.     ParamBlockRec pb;
  501.     OSErr error;
  502.  
  503.     pb.ioParam.ioBuffer = (Ptr)volMountInfo;
  504.     error = PBVolumeMount(&pb);
  505.     *vRefNum = pb.ioParam.ioVRefNum;
  506.     return ( error );
  507. }
  508.  
  509. /*****************************************************************************/
  510.  
  511. pascal    OSErr    Share(short vRefNum,
  512.                       long dirID,
  513.                       StringPtr name)
  514. {
  515.     HParamBlockRec pb;
  516.  
  517.     pb.fileParam.ioNamePtr = name;
  518.     pb.fileParam.ioVRefNum = vRefNum;
  519.     pb.fileParam.ioDirID = dirID;
  520.     return ( PBShareSync(&pb) );
  521. }
  522.  
  523. /*****************************************************************************/
  524.  
  525. pascal    OSErr    FSpShare(const FSSpec *spec)
  526. {
  527.     return ( Share(spec->vRefNum, spec->parID, (StringPtr)spec->name) );
  528. }
  529.  
  530. /*****************************************************************************/
  531.  
  532. pascal    OSErr    Unshare(short vRefNum,
  533.                         long dirID,
  534.                         StringPtr name)
  535. {
  536.     HParamBlockRec pb;
  537.  
  538.     pb.fileParam.ioNamePtr = name;
  539.     pb.fileParam.ioVRefNum = vRefNum;
  540.     pb.fileParam.ioDirID = dirID;
  541.     return ( PBUnshareSync(&pb) );
  542. }
  543.  
  544. /*****************************************************************************/
  545.  
  546. pascal    OSErr    FSpUnshare(const FSSpec *spec)
  547. {
  548.     return ( Unshare(spec->vRefNum, spec->parID, (StringPtr)spec->name) );
  549. }
  550.  
  551. /*****************************************************************************/
  552.  
  553. pascal    OSErr    GetUGEntry(short objType,
  554.                            StringPtr objName,
  555.                            long *objID)
  556. {
  557.     HParamBlockRec pb;
  558.     OSErr error;
  559.  
  560.     pb.objParam.ioObjType = objType;
  561.     pb.objParam.ioObjNamePtr = objName;
  562.     pb.objParam.ioObjID = *objID;
  563.     error = PBGetUGEntrySync(&pb);
  564.     *objID = pb.objParam.ioObjID;
  565.     return ( error );
  566. }
  567.  
  568. /*****************************************************************************/
  569.